
/**
 * Created by Administrator on 2017/1/17.
 *
 * ���������µ������� node  test.js arg1 arg2 arg3����������test.js�л�ȡ����Ĳ���arg1��arg2��arg3��

 var arguments = process.argv.splice(2);

 process��һ��ȫ�ֶ���argv���ص���һ����������в��������顣��һ��Ϊ��node�����ڶ���Ϊִ�е�js������·���������Ǹ����������к�Ĳ���

 C:\prgrm\nodejs721\npm.cmd  install  iconv-lite

 //C:\prgrm\nodejs721\node.exe shwashwa\shwashwa.js 9
 */
function output_txt(html,page) {
    var tim_mod = require("../com.attilax/time/time.js");
    var filM = require("../com.attilax/io/fileUtil.js");

    var fs = require('fs');
    var path = require('path');


//    var page = 5;  // \
    var f = 'c:\\000000shwashwabek\\p' + page + "_" + tim_mod.getTimestamp() + '.txt';


  //  var html = "from clip";

    filM.mkdirsSync_byFilePath(f);
    fs.writeFile(f, html);
    console.log(f);


}
/*
function output_txt_warp()
{

}
*/
function main()
{
    var arguments = process.argv.splice(2);
    var page=arguments[0];
    console.log('-----arguments data:' +  process.argv);
    // -----arguments data:C:\prgrm\nodejs721\node.exe,c:\0workspace\atiplat_shwashwa\shwashwa\shwashwa.js
    console.log('-----arguments data:' + arguments);
    //if multi param  outo is  -----arguments data:9,aa
    // C:\prgrm\nodejs721\node.exe shwashwa\shwashwa.js 9 aa
    getTxtFromClip( function(txt)
    {
        output_txt(txt,page);
        clrClip();
    });
}
main();
var exec = require('child_process').exec;
function clrClip()
{
    var cmd = 'C:\\0workspace\\atiplat_shwashwa\\setclip.exe "--clr"';
    var exeHandler = exec(cmd);
    exeHandler.on('exit', function (code) {
        console.log('--- clrClip exit code:' + code);
    });


}
    function getTxtFromClip(after_fun) {
//var arguments = process.argv.splice(2);
    var iconv = require('iconv-lite');
    var exec = require('child_process').exec;

    var cmd = 'C:\\0workspace\\atiplat_shwashwa\\clip.exe';
    var exeHandler = exec(cmd, {
        encoding: "binary"
    });

    exeHandler.stdout.on('data', function (stdout_data) {
        var str = iconv.decode(stdout_data, 'GBK');
        console.log('-----clip data:' + str);
        after_fun(str);
    });

    exeHandler.on('exit', function (code) {
        console.log('---exit code:' + code);
    });

}

